package com.gemcoder.system.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Map;
import javax.annotation.Resource;
import com.gemcoder.system.bo.Result;
import com.gemcoder.system.service.UsermanagementService;
import cn.hutool.core.util.StrUtil;
import java.util.Map;
import cn.hutool.core.util.ObjectUtil;

@Controller
@RequestMapping("/Usermanagement")
public class UsermanagementController {

    @Resource
    private UsermanagementService UsermanagementService;

    @RequestMapping(value = "/queryUsers")
    @ResponseBody
    public Result queryUsers(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.queryUsers(paramMap);
    }

    @RequestMapping(value = "/resetUsers")
    @ResponseBody
    public Result resetUsers(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.resetUsers(paramMap);
    }

    @RequestMapping(value = "/addUser")
    @ResponseBody
    public Result addUser(@RequestBody(required = false) Map<String, Object> paramMap) {
        // 校验 userName 是否为空
        if (paramMap.get("userName") == null || String.valueOf(paramMap.get("userName")).trim().isEmpty()) {
            return new Result(false, "userName不能为空", null);
        }
        //调用service层的代码
        return UsermanagementService.addUser(paramMap);
    }

    @RequestMapping(value = "/refreshUsers")
    @ResponseBody
    public Result refreshUsers(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.refreshUsers(paramMap);
    }

    @RequestMapping(value = "/initUsers")
    @ResponseBody
    public Result initUsers(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.initUsers(paramMap);
    }

    @RequestMapping(value = "/paginateUsers")
    @ResponseBody
    public Result paginateUsers(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.paginateUsers(paramMap);
    }

    @RequestMapping(value = "/updateUser")
    @ResponseBody
    public Result updateUser(@RequestBody(required = false) Map<String, Object> paramMap) {
        // 校验 userName 是否为空
        if (paramMap.get("userName") == null || String.valueOf(paramMap.get("userName")).trim().isEmpty()) {
            return new Result(false, "userName不能为空", null);
        }
        //调用service层的代码
        return UsermanagementService.updateUser(paramMap);
    }

    @RequestMapping(value = "/getUserDetails")
    @ResponseBody
    public Result getUserDetails(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.getUserDetails(paramMap);
    }

    @RequestMapping(value = "/updateUserRole")
    @ResponseBody
    public Result updateUserRole(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.updateUserRole(paramMap);
    }

    @RequestMapping(value = "/resetUserPassword")
    @ResponseBody
    public Result resetUserPassword(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.resetUserPassword(paramMap);
    }

    @RequestMapping(value = "/deleteUser")
    @ResponseBody
    public Result deleteUser(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.deleteUser(paramMap);
    }

    @RequestMapping(value = "/getAllRoles")
    @ResponseBody
    public Result getAllRoles(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.getAllRoles(paramMap);
    }

    @RequestMapping(value = "/getUserRoles")
    @ResponseBody
    public Result getUserRoles(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.getUserRoles(paramMap);
    }

    @RequestMapping(value = "/toggleUserStatus")
    @ResponseBody
    public Result toggleUserStatus(@RequestBody(required = false) Map<String, Object> paramMap) {
        //如果有需要校验的入参, 请在这里补充代码进行校验
        //调用service层的代码
        return UsermanagementService.toggleUserStatus(paramMap);
    }
}
